package huy.mmt.gamelathinh;

import huy.mmt.gamelathinh.config.Config;
import huy.mmt.gamelathinh.database.MyDataHeaper;
import huy.mmt.gamelathinh.database.ScoreData;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class HighScore extends Activity {

	private MyDataHeaper mData;
	public MySharedPreferences mySharedPreferences;
	public Config config = new Config();
	LinearLayout content;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_highscore);
		mySharedPreferences = new MySharedPreferences(this);
		mySharedPreferences.getThemes();
		content = (LinearLayout) findViewById(R.id.layout_content);
		mData = new MyDataHeaper(this);
		mData.openDatabase();
		// Lấy danh sách 10 người điểm cao nhất them theme

		ArrayList<ScoreData> listScore = mData.getListScore(Config.THEMES);
		
		Log.d("Size list data", String.valueOf(listScore.size()));
		for (int i = 0; i < listScore.size(); i++) {
			content.addView(getView(i, listScore.get(i)));
		}
		String theme = config.getNameTheme(Config.THEMES);
		String dif = config.getNameDif(Config.Do_kho);
		TextView txt_theme = (TextView)findViewById(R.id.item_theme);
		txt_theme.setText("Chủ đề:"+theme +"- Độ khó: "+ dif);
		mData.closeDatabase();
	}

	public View getView(int stt, ScoreData score) {
		// find text
		View v = View.inflate(this, R.layout.itemlayout_heightcore, null);
		TextView txt_stt = (TextView) v.findViewById(R.id.item_stt);
		TextView txt_name = (TextView) v.findViewById(R.id.item_name);
		TextView txt_dollar = (TextView) v.findViewById(R.id.item_score);
		
		// set text
		txt_stt.setText("" + (stt + 1));
		txt_name.setText(score.getNamePlayer());
		txt_dollar.setText(String.valueOf(score.getScore()));
		return v;
	}

	public void back(View v) {
		Main.click.start();
		this.finish();
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		Main.click.start();
		this.finish();
		super.onBackPressed();
	}
}
